﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DeJC.DAL.Model;

namespace DeJC.BLL.Managers {
    public static class UserAddressManager {
        public static IEnumerable<UserAddress> GetUserAddresss() {
            IEnumerable<UserAddress> userAddresss;
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                userAddresss=unitOfWork.UserAddressRepository.GetAll();
            }
            return userAddresss;
        }

        public static bool AddUserAddress(UserAddress userAddress) {
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                unitOfWork.UserAddressRepository.Add(userAddress);
                unitOfWork.Save();
            }
            return true;
        }

        // public bool UpdateUserAddress(UserAddress userAddress, int id)
        // {
        // using (UnitOfWork unitOfWork = new UnitOfWork())
        // {
        // var userAddressEntity = unitOfWork.UserAddressRepository.GetById(id);
        // userAddressEntity.Title = userAddress.Title;
        // userAddressEntity.FirstName = userAddress.FirstName;
        // userAddressEntity.LastName = userAddress.LastName;
        // userAddressEntity.ModifiedDate = DateTime.Now;
        // unitOfWork.Save();
        // }
        // return true;
        // }

        public static bool DeleteUserAddress(int id) {
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                UserAddress userAddress=unitOfWork.UserAddressRepository.GetById(id);
                userAddress.Deleted=true;
                userAddress.DeletedDate=DateTime.Now;
                unitOfWork.Save();
            }
            return true;
        }

        // public List<UserAddress> GetUserAddressPaged(int page, int rows, out int totalCount)
        // {
        // List<UserAddress> userAddresss;
        // using (UnitOfWork unitOfWork = new UnitOfWork())
        // {
        // userAddresss = unitOfWork.UserAddressRepository.GetUserAddressPaged
        // (page, rows, out totalCount);
        // }
        // return userAddresss;
        // }
        public static UserAddress GetById(int id) {
            UserAddress userAddress;
            using(UnitOfWork unitOfWork=new UnitOfWork()) {
                userAddress=unitOfWork.UserAddressRepository.GetById(id);
            }
            return userAddress;
        }
    }
}
